#include "krtpch.h"

#include "../../include/Core/Transform.h"

namespace krt {

	Transform::Transform(const glm::mat4& trans)
		: transMat(trans), intransMat(glm::inverse(trans))
	{}

	Transform::Transform(const glm::mat4& trans, const glm::mat4& intrans)
		: transMat(trans), intransMat(intrans)
	{}

	Ref<Transform> Transform::Create(const glm::vec3& position, const glm::vec3& rotation, float angle, const glm::vec3& scale) {
		auto transMat = glm::mat4(1.0);
		transMat = glm::translate(transMat, position);
		transMat = glm::rotate(transMat, angle, rotation);
		transMat = glm::scale(transMat, scale);

		return MakeRef<Transform>(transMat);
	}

	Ref<Transform> Transform::Create(const glm::vec3& position, const glm::vec3& scale) {
		auto transMat = glm::mat4(1.0);
		transMat = glm::translate(transMat, position);
		transMat = glm::scale(transMat, scale);

		return MakeRef<Transform>(transMat);
	}

	Transform Transform::Inverse(const Transform& t) {
		return Transform(t.intransMat, t.transMat);
	}

	Ref<Transform> Transform::Inverse(Ref<Transform> t) {
		return MakeRef<Transform>(t->intransMat, t->transMat);
	}
}